<?php
/** .-------------------------------------------------------------------
 * |  Software: [HDCMS framework]
 * |      Site: www.hdcms.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

namespace web\admin\controller;

class Typeattr extends Common{
    private $db;
    public function __construct(){
        parent::__construct();
        $this->db = new \system\model\Typeattr();
    }
    //首页显示
    public function index(){
        $tid = q('get.tid',0,'intval');
        $data = $this->db->getAll();
         View::with('tid',$tid);
        View::with('data',$data)->make();
    }
    //动作o
	public function add(){
        if(IS_POST){
            $tid = q('get.tid',0,intval);
            if($this->db->store()){
                message('添加成功',U('index',array('tid'=>$tid)),'success');
            }
               message($this->db->getError(),'','error');
        }
        View::make();

	}
    //编辑
    public function edit(){
        if(IS_POST){
            $tid = q('get.tid',0,intval);
            if($this->db->edit()){
                message('编辑成功',U('index',array('tid'=>$tid)),'success');
            }
             message($this->db->getError(),'','error');

        }
        //获取旧数据
        $taid = q('get.taid',0,intval);
        $oldData = $this->db->where('taid',$taid)->first();
       // p($oldData);die;
        View::with('oldData',$oldData)->make();
    }
    //删除
    public function del(){
        $taid = q('get.taid',0,intval);
        $this->db->where('taid',$taid)->delete();
        message('删除成功','','success');
    }
}
